package com.bank.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.schema.ScalarType;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ParameterType;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.List;

import static java.util.Collections.singletonList;


@EnableOpenApi
@Configuration
public class Swagger2Config {


    @Bean
    public Docket createRestApi(){

        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any()).build()
                .globalRequestParameters(singletonList(new springfox.documentation.builders.RequestParameterBuilder()
                        // 不能叫Authorization
                        .name("satoken")
                        .description("登录token")
                        .in(ParameterType.HEADER)
                        .required(true)
                        .query(q -> q.model(m -> m.scalarModel(ScalarType.STRING)))
                        .build()));
    }


    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("开户平台API")
                .description("This is a restful api document of Kitty.")
                .version("1.0")
                .build();
    }
}